(* This file is part of IsoType.
 *
 * IsoType is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * IsoType is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with IsoType.  If not, see <http://www.gnu.org/licenses/>.
 *)

let prefix_to s index =
  String.sub s 0 index

let suffix_from s index =
  String.sub s index (String.length s - index)

let between s from_c to_c = 
  let prefix = prefix_to s (String.rindex s to_c) in 
  suffix_from prefix ((String.index prefix from_c) + 1)
 
let split s ch =
  let rec aux l s =
    try
      let index = String.rindex s ch in
	aux ((suffix_from s (index + 1))::l) (prefix_to s index)
    with
	Not_found -> s::l
  in
    aux [] s

let begins_with s s' =
  String.length s >= String.length s' && prefix_to s (String.length s') = s'
